package com.example.yzx.allriddle.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by ibm on 2015/9/11.
 */
public class Db extends SQLiteOpenHelper {
    public Db(Context context, int version) {
        super(context, "db", null, version);//可以根据最后一个参数的version来完成表的自动创建和升级
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE user(" +
                "uid integer primary key autoincrement, " +
                "name TEXT DEFAULT \"\"," + "word TEXT DEFAULT \"\"," + "grade float DEFAULT \"\")";
        db.execSQL(sql);
        System.out.println("创建数据库：" + sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {//更新数据库
        String sql = "ALTER TABLE user ADD COLUMN mark TEXT DEFAULT \"\"";
        System.out.println("更新数据库：" + sql);
        db.execSQL(sql);
    }
}